//package com.dfs.parent.gateway.config;
//
//import com.dfs.parent.common.core.constant.GrayConstant;
//import com.dfs.parent.gateway.filter.GrayReactiveLoadBalancerClientFilter;
//import com.dfs.parent.gateway.props.GrayAppointProperties;
//import com.dfs.parent.gateway.props.GrayBatchProperties;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.autoconfigure.AutoConfigureBefore;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.cloud.context.config.annotation.RefreshScope;
//import org.springframework.cloud.gateway.config.GatewayLoadBalancerProperties;
//import org.springframework.cloud.gateway.config.GatewayReactiveLoadBalancerClientAutoConfiguration;
//import org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter;
//import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
///**
// * @Description TODO
// * @Author dahong
// * @Date 2024/2/18 03:26
// */
//@Slf4j
//@Configuration
//@EnableConfigurationProperties(GatewayLoadBalancerProperties.class)
//@AutoConfigureBefore(GatewayReactiveLoadBalancerClientAutoConfiguration.class)
//@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
//public class GrayLoadBalancerClientConfig {
//    /**
//     * 是否开启灰度
//     * spring cloud性@RefreshScope，@Configuration配置类在应用启动时会被加载并创建Bean，而@RefreshScope注解会导致Bean在运行时重新创建。
//     *
//     * Bean在你的代码中行时@RefreshScope动态刷新时，会导致Bean加载不上的问题。
//     *
//     * 为了解决这个问题，你可以将@Value("${dfs.gray.rule.enabled}")注解移动到gatewayLoadBalancerClientFilter方法中，而不是放在配置类的字段上。
//     * 这样，每次调用gatewayLoadBalancerClientFilter方法时，都会动态获取dfs.gray.rule.enabled的值。
//     * @param clientFactory
//     * @param properties
//     * @param isGray
//     * @return
//     */
//    @Bean
//    @RefreshScope
//    public ReactiveLoadBalancerClientFilter gatewayLoadBalancerClientFilter(LoadBalancerClientFactory clientFactory
//            , GatewayLoadBalancerProperties properties, @Value("${dfs.gray.rule.enabled}") String isGray
//            ,GrayBatchProperties grayBatchProperties, GrayAppointProperties grayAppointProperties) {
//        if(GrayConstant.GRAY_TAG_VALUE_TRUE.equals(isGray)) {
//            log.info("开启灰度==》dfs.gray.rule.enabled={}",isGray);
//            return new GrayReactiveLoadBalancerClientFilter(clientFactory, properties,grayBatchProperties,grayAppointProperties);
//        }else{
//            log.info("关闭灰度==》dfs.gray.rule.enabled={}",isGray);
//            return new ReactiveLoadBalancerClientFilter(clientFactory, properties);
//        }
//    }
//
//
//}
